package Tests;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

import FileIO.*;
import ParsingSys.*;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		//create menu
		System.out.println("*********************************************************************");
		System.out.println("Please choose:");
		System.out.println("Mode 1: (Input: Finite partial order Output: Sequence of Values)");
		System.out.println("Mode 2: (Input: Finite partial order and sequence of values Output: True if the sequence satistifes the partial order, False otherwise");
		System.out.println("All input and output are read from and generated to files");
		System.out.println("*********************************************************************");
		System.out.print("Your option (1 or 2):");
		
		BufferedReader testNumber = new BufferedReader(new InputStreamReader(System.in));
		String option=null;
		try{
			option=testNumber.readLine();
			
		} catch(IOException e){
			System.out.println("Error reading option");
			System.exit(1);
		}
		if (option.equals("1")){	//mode 1
			System.out.println(option);
			ArrayList<String> fileLines = InputReader.readFile("./src/tests/test1.txt");
			Parser p = new Parser(fileLines);
			ArrayList<Value> parsedValues=p.parse();
			OutputManager.creatFile("./src/tests/output1.txt", parsedValues);
			
			fileLines = InputReader.readFile("./src/tests/test2.txt");
			Parser p2 = new Parser(fileLines);
			parsedValues=p2.parse();
			OutputManager.creatFile("./src/tests/output2.txt", parsedValues);  
				
		}
		if (option.equals("2")){	//mode 2
			System.out.println(option);
			ArrayList<String> inputPartialOrder = InputReader.readFile("./src/tests/test1.txt");
			ArrayList<String> inputSequenceValue = InputReader.readFile("./src/tests/output1.txt");
			int index = inputSequenceValue.indexOf("");
			ArrayList<String> inputSequenceValues = new ArrayList<String>();
			for(int i=index+1;i<inputSequenceValue.size();i++)
			{
				inputSequenceValues.add(inputSequenceValue.get(i));
			}
			
			Parser p = new Parser(inputPartialOrder,inputSequenceValues);
			boolean match=p.match();
			OutputManager.createOutputMode2("./src/tests/output1.txt", match);
			System.out.println(match);
			
			//try another case
			inputSequenceValue.clear();
			inputSequenceValues.clear();
			inputPartialOrder = InputReader.readFile("./src/tests/test1.txt");
			inputSequenceValue = InputReader.readFile("./src/tests/output2.txt");
			index = inputSequenceValue.indexOf("");
			for(int i=index+1;i<inputSequenceValue.size();i++)
			{
				inputSequenceValues.add(inputSequenceValue.get(i));
			}
			p = new Parser(inputPartialOrder,inputSequenceValues);
			match=p.match();
			OutputManager.createOutputMode2("./src/tests/output2.txt", match);
			System.out.println(match);
		}
				
		
	}

}